package cn.xinfei.xdecision.common.service.component.decisiontable.impl;

import cn.xinfei.xdecision.common.dao.component.decisiontable.DecisionTablesDetailConditionMapper;
import cn.xinfei.xdecision.common.dao.component.decisiontable.DecisionTablesMapper;
import cn.xinfei.xdecision.common.model.common.PageResult;
import cn.xinfei.xdecision.common.model.common.ResponseEntityDto;
import cn.xinfei.xdecision.common.model.component.ComponentVersionVo;
import cn.xinfei.xdecision.common.model.component.ComponentVo;
import cn.xinfei.xdecision.common.model.component.CopyToFolderReqVo;
import cn.xinfei.xdecision.common.model.component.decisiontable.DecisionTables;
import cn.xinfei.xdecision.common.model.component.decisiontable.DecisionTablesVersion;
import cn.xinfei.xdecision.common.model.component.decisiontable.vo.DecisionTablesVersionVo;
import cn.xinfei.xdecision.common.model.component.decisiontable.vo.DecisionTablesVo;
import cn.xinfei.xdecision.common.model.component.dependency.EngineNodeComponentRel;
import cn.xinfei.xdecision.common.model.component.dependency.resp.DecisionComponentDependencyResp;
import cn.xinfei.xdecision.common.model.component.guiderule.vo.RuleListReqVo;
import cn.xinfei.xdecision.common.model.component.request.ListParam;
import cn.xinfei.xdecision.common.model.login.SessionManager;
import cn.xinfei.xdecision.common.service.common.sso.SSOService;
import cn.xinfei.xdecision.common.service.common.sso.dto.SSOUserInfoReqDto;
import cn.xinfei.xdecision.common.service.common.sso.dto.SSOUserInfoRespDto;
import cn.xinfei.xdecision.common.service.component.ComponentCommonContext;
import cn.xinfei.xdecision.common.service.component.ComponentCommonService;
import cn.xinfei.xdecision.common.service.component.decisiontable.DecisionTablesService;
import cn.xinfei.xdecision.common.service.component.decisiontable.DecisionTablesVersionService;
import cn.xinfei.xdecision.common.service.component.dependency.EngineNodeComponentRelService;
import cn.xinfei.xdecision.common.service.utils.CodeGenerateUtil;
import cn.xinfei.xdecision.common.utils.constant.SysConstant;
import cn.xinfei.xdecision.common.utils.enums.enginex.ComponentStatusEnum;
import cn.xinfei.xdecision.common.utils.enums.enginex.ComponentVersionStatusEnum;
import cn.xinfei.xdecision.common.utils.enums.enginex.EngineVersionStatusEnum;
import cn.xinfei.xdecision.common.utils.exception.ApiException;
import cn.xinfei.xdecision.common.utils.exception.enums.ErrorCodeEnum;
import cn.xinfei.xdecision.common.utils.util.BeanUtilsPlus;
import cn.xinfei.xdecision.common.utils.util.FutureUtils;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;

import static cn.xinfei.xdecision.common.utils.exception.enums.ErrorCodeEnum.COMPONENT_COPY_ERROR;
import static cn.xinfei.xdecision.common.utils.exception.util.ApiExceptionUtil.exception;

/**
 * (DecisionTables)表服务实现类
 */
@Service("decisionTablesService")
@Slf4j
public class DecisionTablesServiceImpl extends ServiceImpl<DecisionTablesMapper, DecisionTables> implements DecisionTablesService, ComponentCommonService {

    @Resource
    private SSOService ssoService;

    @Resource
    private DecisionTablesVersionService versionService;

    @Resource(name = "componentAsyncExecutor")
    private ExecutorService bizProcessorThreadPool;

    @Resource
    private CodeGenerateUtil codeGenerateUtil;

    @Resource
    private TransactionTemplate transactionTemplate;

    @Resource
    private DecisionTablesServiceImpl decisionTablesService;

    @Resource
    private DecisionTablesDetailConditionMapper decisionTablesDetailConditionMapper;

    @Resource
    private EngineNodeComponentRelService engineNodeComponentRelService;

    @Resource
    private DecisionTablesMapper decisionTablesMapper;

    @Override
    public DecisionTablesVo queryById(Long id) {
        DecisionTablesVo decisionTablesVo = new DecisionTablesVo();
        //查询决策表主表信息
        DecisionTables decisionTables = this.getById(id);
        if (Objects.isNull(decisionTables)) {
            return decisionTablesVo;
        }
        BeanUtils.copyProperties(decisionTables, decisionTablesVo);
        //规则状态描述
        decisionTablesVo.setStatusDesc(Objects.requireNonNull(ComponentStatusEnum.get(decisionTablesVo.getStatus())).getName());
        //全部版本信息
        List<DecisionTablesVersionVo> tablesVersionVos = versionService.queryVersionByTablesCodes(
                Collections.singletonList(decisionTablesVo.getCode()), null);
        if (CollectionUtils.isEmpty(tablesVersionVos)) {
            return decisionTablesVo;
        }
        //当前版本
        DecisionTablesVersionVo decisionTablesVersionVo = tablesVersionVos.stream()
                .max(Comparator.comparing(DecisionTablesVersionVo::getId)).orElse(null);
        if (Objects.isNull(decisionTablesVersionVo)) {
            return decisionTablesVo;
        }
        decisionTablesVo.setLastVersionStatus(decisionTablesVersionVo.getStatus())
                //最新版本状态描述
                .setLastVersionStatusDesc(Objects.requireNonNull(EngineVersionStatusEnum.get(decisionTablesVersionVo.getStatus())).getName())
                //当前版本
                .setLastVersion(decisionTablesVersionVo.getVersionNo())
                //版本说明
                .setVersionDesc(decisionTablesVersionVo.getDescription())
                //是否存在新建版本
                .setIsNewVersion(tablesVersionVos.stream().anyMatch(x -> Objects.equals(x.getStatus(), EngineVersionStatusEnum.NEW.getStatus())))
                .setVersionList(Lists.newArrayList(decisionTablesVersionVo));
        return decisionTablesVo;
    }

    @Override
    public DecisionTablesVo queryDetailsById(Long id) {
        DecisionTablesVo decisionTablesVo = queryById(id);
        decisionTablesVo.setVersionList(
                versionService.queryVersionByTablesCodes(
                        Collections.singletonList(decisionTablesVo.getCode()),
                        EngineVersionStatusEnum.ENABLE.getStatus()));
        return decisionTablesVo;
    }

    @Override
    public ResponseEntityDto<PageResult<List<DecisionTablesVo>, DecisionTables>> queryByEntity(ListParam listParam) {
        List<Long> orgIdList = SessionManager.getLoginAccount().getOrgIdList();
        if (CollectionUtils.isEmpty(orgIdList)) {
            return ResponseEntityDto.success(new PageResult<>());
        }
        //决策表
        LambdaUpdateWrapper<DecisionTables> lbd = new LambdaUpdateWrapper<>();
        if (StringUtils.isNotEmpty(listParam.getCondition())) {
            lbd.eq(DecisionTables::getCode, listParam.getCondition())
                    .or().like(DecisionTables::getName, listParam.getCondition());
        }
        if (Objects.nonNull(listParam.getFolderId())) {
            lbd.eq(DecisionTables::getFolderId, listParam.getFolderId());
        }
        lbd.in(DecisionTables::getOrganId, orgIdList);
        PageMethod.startPage(listParam.getPageNo(), listParam.getPageSize());
        //排序按照启用，更新时间倒叙
        List<DecisionTables> decisionTables = this.list(lbd.last("order by status = 1 desc,updated_time desc"));
        if (CollectionUtils.isEmpty(decisionTables)) {
            return PageResult.success(new ArrayList<>(), new PageInfo<>());
        }
        PageInfo<DecisionTables> pageInfo = new PageInfo<>(decisionTables);
        List<DecisionTablesVo> decisionTablesVos = BeanUtilsPlus.copyElements(decisionTables, DecisionTablesVo::new);
        //版本号
        List<DecisionTablesVersionVo> decisionTablesVersionVos = versionService.queryVersionByTablesCodes(
                decisionTablesVos.stream().map(DecisionTables::getCode).collect(Collectors.toList()), null);
        Map<String, List<DecisionTablesVersionVo>> versionMap = decisionTablesVersionVos
                .stream().collect(Collectors.groupingBy(DecisionTablesVersionVo::getDecisionTablesCode));
        //更新人信息
        SSOUserInfoReqDto ssoUserInfoReqDto = new SSOUserInfoReqDto();
        ssoUserInfoReqDto.setId(new ArrayList<>(
                decisionTables.stream().map(DecisionTables::getUpdateUserId).collect(Collectors.toSet())));
        Map<Long, String> sysMap = ssoService.getUserInfos(ssoUserInfoReqDto).stream()
                .collect(Collectors.toMap(SSOUserInfoRespDto::getId, SSOUserInfoRespDto::getName));
        decisionTablesVos.forEach(x -> {
                    List<DecisionTablesVersionVo> versionVos = versionMap.getOrDefault(x.getCode(), new ArrayList<>());
                    //状态描述
                    x.setStatusDesc(Objects.requireNonNull(ComponentStatusEnum.get(x.getStatus())).getName())
                            //更新人信息
                            .setUpdatedUserName(sysMap.getOrDefault(x.getUpdateUserId(), SysConstant.EMPTY_STRING))
                            //版本集合
                            .setVersionList(versionVos);
                    //最新版本号
                    Long lastVersion = versionVos.stream()
                            .max(Comparator.comparing(DecisionTablesVersionVo::getVersionNo))
                            .map(DecisionTablesVersionVo::getVersionNo).orElse(0L);
                    x.setLastVersion(lastVersion).setLastVersionDesc("V" + lastVersion);
                }
        );
        return PageResult.success(decisionTablesVos, pageInfo);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long checkAndSaveTables(DecisionTablesVo decisionTablesVo) {
        if (StringUtils.isEmpty(decisionTablesVo.getName())) {
            throw new ApiException(ErrorCodeEnum.NAME_CAN_NOT_BE_NULL);
        }
        //只能修改最新版本状态为‘新建’的规则
        if (!CollectionUtils.isEmpty(decisionTablesVo.getVersionList())) {
            DecisionTablesVersionVo versionVo = decisionTablesVo.getVersionList().get(0);
            if (!Objects.equals(versionVo.getStatus(), ComponentVersionStatusEnum.NEW.getStatus())) {
                throw new ApiException(ErrorCodeEnum.DECISION_SAVE_PRE_CHECK_ERROR_001.getCode(),
                        ErrorCodeEnum.DECISION_SAVE_PRE_CHECK_ERROR_001.getMessage());
            }
            //判断当前版本的状态和传进来的状态是否一致
            checkVersionStatus(versionVo);
            decisionTablesVo.getVersionList().forEach(DecisionTablesVersionVo::recursionNodeType);
        }
        //decisionTablesVo.setStatus(ComponentStatusEnum.NEW.getStatus());
        saveDecisionTables(decisionTablesVo);
        return decisionTablesVo.getId();
    }

    private void checkVersionStatus(DecisionTablesVersionVo versionVo) {
        if (Objects.nonNull(versionVo.getId()) && Objects.nonNull(versionVo.getStatus())) {
            DecisionTablesVersion decisionTablesVersion = versionService.getById(versionVo.getId());
            if (!Objects.equals(decisionTablesVersion.getStatus(), versionVo.getStatus())) {
                log.error("传进来的版本状态和数据库中不一致，入参==》{}", JSON.toJSONString(decisionTablesVersion));
                throw new ApiException(ErrorCodeEnum.PARAMS_EXCEPTION.getCode(),
                        ErrorCodeEnum.PARAMS_EXCEPTION.getMessage());
            }
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveDecisionTables(DecisionTablesVo decisionTablesVo) {
        if (Objects.isNull(decisionTablesVo.getId())) {
            //初始化基本参数
            initParam(decisionTablesVo);
        }
        //拷贝VO到Info对象
        DecisionTables decisionTables = BeanUtilsPlus.copyProperties(decisionTablesVo, DecisionTables::new);
        if (Objects.nonNull(decisionTablesVo.getId())) {
            decisionTables.setCode(null);
        }
        decisionTables.setOrganId(SessionManager.getLoginAccount().getOrganId());
        boolean save = this.saveOrUpdate(decisionTables);
        decisionTablesVo.setId(decisionTables.getId());
        if (!save) {
            throw new ApiException(ErrorCodeEnum.DECISION_SAVE_ERROR.getCode(), ErrorCodeEnum.DECISION_SAVE_ERROR.getMessage());
        }
        List<DecisionTablesVersionVo> versionList = decisionTablesVo.getVersionList();
        if (!CollectionUtils.isEmpty(versionList)) {
            AtomicLong at = new AtomicLong();
            versionList.forEach(x -> {
                x.setDecisionTablesCode(decisionTables.getCode());
                if (Objects.isNull(x.getId())) {
                    x.setOrganId(SessionManager.getLoginAccount().getOrganId());
                    x.setVersionNo(at.incrementAndGet());
                }
            });
            //保存版本
            versionService.addVersionList(versionList);
        }
    }


//    @Override
//    @Transactional
//    public DecisionTablesVo updateDecisionTables(DecisionTablesVo vo) {
//        if (vo.getId() == null) {
//            throw new ApiException(ErrorCodeEnum.PARAMS_EXCEPTION.getCode(), ErrorCodeEnum.PARAMS_EXCEPTION.getMessage());
//        }
////        SSOUser sysUser = SessionManager.getLoginAccount();
////        vo.setModifier(sysUser.getId());
//        DecisionTables decisionTables = new DecisionTables();
//        BeanUtils.copyProperties(vo, decisionTables);
//        //修改主表
//        boolean updateResult = this.updateById(decisionTables);
//        if (!updateResult) {
//            throw new ApiException(ErrorCodeEnum.SERVER_ERROR.getCode(), ErrorCodeEnum.SERVER_ERROR.getMessage());
//        }
//        Long decisionTablesId = decisionTables.getId();
//        List<DecisionTablesVersionVo> versionList = vo.getDecisionTablesVersionList();
//        if (versionList != null && versionList.size() > 0) {
//            versionService.updateVersion(versionList.get(0));
//        }
//        return this.queryById(decisionTablesId);
//    }

    @Override
    public boolean updateParent(List<Long> ids, Long folderId) {
        LambdaUpdateWrapper<DecisionTables> wrapper = new LambdaUpdateWrapper<>();
        wrapper.in(DecisionTables::getId, ids).set(DecisionTables::getFolderId, folderId);
        DecisionTables decisionTables = new DecisionTables();
        decisionTables.setFolderId(folderId);
        return this.update(decisionTables, wrapper);
    }

    @Override
    public List<String> queryFieldEnByDecisionTablesVersionId(Long decisionTablesVersionId) {
        return versionService.queryFieldEnByVersionId(decisionTablesVersionId);
    }

    //唯一性检查
    private void checkUniqueness(DecisionTablesVo vo) {
        DecisionTables decisionTables = new DecisionTables();
        decisionTables.setName(vo.getName());
        decisionTables.setFolderId(vo.getFolderId());
        DecisionTables info = this.getOne(new QueryWrapper<>(decisionTables));
        if (info != null) {
            throw new ApiException(ErrorCodeEnum.DECISION_NAME_REPEAT.getCode(), ErrorCodeEnum.DECISION_NAME_REPEAT.getMessage());
        }
    }

    //新插入数据的准备工作
    private void initParam(DecisionTablesVo vo) {
        this.checkUniqueness(vo);
        vo.setOrganId(SessionManager.getLoginAccount().getOrganId());
    }

    @Override
    public DecisionTablesVo queryByVersionId(String decisionTableCode, long versionNo) {
        //查询版本
        List<DecisionTablesVersionVo> versionVos = versionService.queryByDecisionTableCodeAndVersionNo(decisionTableCode, versionNo);
        if (CollectionUtils.isEmpty(versionVos)) {
            return null;
        }
        DecisionTablesVersionVo versionVo = versionVos.get(0);
        String decisionTablesCode = versionVo.getDecisionTablesCode();

        //根据版本信息查询决策表主表信息
        QueryWrapper<DecisionTables> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("code", decisionTablesCode);
        DecisionTables decisionTables = this.getOne(queryWrapper);

        if (decisionTables == null) {
            log.error("没有查询出决策表实例,versionNo={},decisionTableCode={}", versionNo, decisionTablesCode);
            return null;
        }

        DecisionTablesVo decisionTablesVo = new DecisionTablesVo();
        BeanUtils.copyProperties(decisionTables, decisionTablesVo);
        decisionTablesVo.setExecuteVersion(versionVo);
        return decisionTablesVo;
    }

    @Override
    public DecisionTablesVo queryByVersionId(Long id) {
        //查询版本
        DecisionTablesVersionVo versionVo = versionService.queryById(id);

        String decisionTablesCode = versionVo.getDecisionTablesCode();

        //根据版本信息查询决策表主表信息
        QueryWrapper<DecisionTables> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("code", decisionTablesCode);
        DecisionTables decisionTables = this.getOne(queryWrapper);

        if (decisionTables == null) {
            log.error("没有查询出决策表实例,versionId={},decisionTableCode={}", id, decisionTablesCode);
            return null;
        }

        DecisionTablesVo decisionTablesVo = new DecisionTablesVo();
        BeanUtils.copyProperties(decisionTables, decisionTablesVo);
        decisionTablesVo.setExecuteVersion(versionVo);
        return decisionTablesVo;
    }

    @Override
    public void copyDecisionTables(CopyToFolderReqVo req) {
        //查询决策表主表信息
        List<DecisionTables> decisionTables = this.listByIds(req.getIds());
        if (CollectionUtils.isEmpty(decisionTables)) {
            return;
        }
        List<Future<Void>> allFutureList = Lists.newArrayList();
        List<String> errorCodeList = new CopyOnWriteArrayList<>();
        decisionTables.forEach(x -> allFutureList.add(CompletableFuture.runAsync(() -> {
            //查询规则
            x.setUpdateUserId(null);
            x.setUpdatedTime(null);
            DecisionTablesVo decisionTablesVo = BeanUtilsPlus.copyProperties(x, DecisionTablesVo::new);
            decisionTablesVo.setName(req.getNamePrefix() + decisionTablesVo.getName() + req.getNameSuffix());
            decisionTablesVo.setFolderId(req.getFolderId());
            decisionTablesVo.setId(null);
            //查询全部版本信息
            List<Long> versionIds =
                    versionService.queryVersionByTablesCodes(Collections.singletonList(decisionTablesVo.getCode()), null)
                            .stream().map(DecisionTablesVersionVo::getId).collect(Collectors.toList());
            //查询明细
            List<DecisionTablesVersionVo> versionVos =
                    versionIds.stream().map(id -> {
                        DecisionTablesVersionVo versionVo = versionService.queryById(id);
                        versionVo.recurrenceSetIdIsNull();
                        return versionVo;
                    }).collect(Collectors.toList());
            decisionTablesVo.setVersionList(versionVos);
            transactionTemplate.execute(status -> {
                try {
                    decisionTablesVo.setCode(codeGenerateUtil.generateYMDCode(SysConstant.JCB_PREFIX, null));
                    decisionTablesService.saveDecisionTables(decisionTablesVo);
                    return Boolean.TRUE;
                } catch (Exception e) {
                    status.setRollbackOnly();
                    log.error("决策表复制失败，具体信息==>{}", JSON.toJSONString(x), e);
                    errorCodeList.add(x.getCode());
                    return Boolean.FALSE;
                }
            });
        }, bizProcessorThreadPool)));
        allFutureList.forEach(x -> FutureUtils.futureGet(x, ErrorCodeEnum.DECISION_COPY_ERROR));

        if (!CollectionUtils.isEmpty(errorCodeList)) {
            throw exception(COMPONENT_COPY_ERROR, errorCodeList);
        }

    }

    @Override
    public List<Long> queryByFolderId(Long folderId) {
        List<DecisionTables> list = this.list(new LambdaQueryWrapper<DecisionTables>()
                .select(DecisionTables::getId)
                .eq(DecisionTables::getFolderId, folderId));
        if (!CollectionUtils.isEmpty(list)) {
            return list.stream().map(DecisionTables::getId).collect(Collectors.toList());
        }
        return new ArrayList<>();
    }

    @Override
    public void logicalDelete(List<Long> ids) {
        this.removeByIds(ids);
    }

    @Override
    public void updateDecisionTables(List<Long> ids, Integer status, String errorMsg) {
        List<DecisionTables> decisionTablesList = this.listByIds(ids);
        String errInfo = decisionTablesList.stream()
                .filter(x -> Objects.equals(x.getStatus(), status))
                .map(DecisionTables::getCode).collect(Collectors.joining(SysConstant.COMMA));
        if (StringUtils.isNotEmpty(errInfo)) {
            throw new ApiException(
                    ErrorCodeEnum.DECISION_UPDATE_ERROR.getCode()
                    , ErrorCodeEnum.DECISION_UPDATE_ERROR.getMessage() + "," + errorMsg + ",决策表规则编号：" + errInfo);
        }
        //停用时需校验是否被决策流依赖
        if (ComponentStatusEnum.DISABLE.getStatus().equals(status)) {
            List<EngineNodeComponentRel> dependencies =
                    engineNodeComponentRelService.getRelByComponentCode(decisionTablesList.stream().map(DecisionTables::getCode).collect(Collectors.toList()));
            if (!CollectionUtils.isEmpty(dependencies)) {
                throw exception(
                        ErrorCodeEnum.COMPONENT_STATUS_UPDATE_ERROR,
                        "存在依赖关系",
                        dependencies.stream()
                                .map(EngineNodeComponentRel::getComponentCode)
                                .distinct()
                                .collect(Collectors.joining(SysConstant.COMMA)));
            }
        }
        DecisionTables decisionTables = new DecisionTables();
        decisionTables.setStatus(status);
        this.update(decisionTables, new LambdaQueryWrapper<DecisionTables>().in(DecisionTables::getId, ids));
    }

    @Override
    public Boolean hasNewVersion(String ruleCode) {
        return !versionService.queryVersionByTablesCodes(
                Collections.singletonList(ruleCode), ComponentVersionStatusEnum.NEW.getStatus()).isEmpty();
    }

    @Override
    public List<ComponentVo> listComponentInfoByIds(String ids) {
        //主表信息
        List<DecisionTables> decisionTables = this.listByIds(Arrays.asList(ids.split(SysConstant.COMMA)));
        if (CollectionUtils.isEmpty(decisionTables)) {
            return new ArrayList<>();
        }
        Map<String, List<DecisionTablesVersion>> collect = versionService.queryVersionByTablesCodes(
                decisionTables.stream().map(DecisionTables::getCode).collect(Collectors.toList()), ComponentVersionStatusEnum.ENABLE.getStatus()).stream()
                .collect(Collectors.groupingBy(DecisionTablesVersion::getDecisionTablesCode));
        if (collect.isEmpty()) {
            return new ArrayList<>();
        }
        List<ComponentVo> componentVos = BeanUtilsPlus.copyElements(decisionTables, ComponentVo::new);
        componentVos.forEach(x -> {
                    List<ComponentVersionVo> componentVersionVos =
                            BeanUtilsPlus.copyElements(collect.get(x.getCode()), ComponentVersionVo::new);
                    ComponentCommonContext.swapVersionNoDesc(componentVersionVos);
                    x.setVersionList(componentVersionVos)
                            .setStatusDesc(Objects.requireNonNull(ComponentStatusEnum.get(x.getStatus())).getName());
                }
        );
        return componentVos;
    }

    @Override
    public List<DecisionComponentDependencyResp> getComponentCodeByVarCodes(List<String> varCodes) {
        return decisionTablesDetailConditionMapper.getComponentCodeByVarCodes(varCodes);
    }

    @Override
    public List<String> getFieldCodesByComponentCodes(List<ComponentVo> componentCodes) {
        if (CollectionUtils.isEmpty(componentCodes)) {
            return Collections.emptyList();
        }
        return decisionTablesDetailConditionMapper.getFieldCodesByComponentCodes(componentCodes);
    }

    @Override
    public List<ComponentVo> listComponentInfoByCon(RuleListReqVo ruleListReqVo) {
        return decisionTablesMapper.listComponentInfoByCon(ruleListReqVo);
    }

}
